<?php
declare (strict_types = 1);

namespace app\model\table\union;

use app\model\BaseModel;
use app\model\table\user\User;
use think\Model;

/**
 * @mixin \think\Model
 */
class Union extends BaseModel
{
    protected $table = 'app_union';

    // 是否全表缓存到redis
    public $tableToRedis = true;

    // 该表缓存到redis的策略
    public $tableToRedisKey = ['id'];

    public $joinWithList=array(
        'UserInfo'=>array(
            'selfColumn'=>'user_id',
            'joinObj'=> User::class,
            'joinColumn'=>'id',
            'selectColumn'=>'id,name'
        ),
    );
    /**
     * 刷新工会成员数量
     * @return void
     */
    public function flushMember($id)
    {
        $count = User::instance()->findMore(['union_id'=>$id], true);
        $postData = array(
            'id' => $id,
            'member_now' => count($count)
        );
        Union::instance()->updateOne($postData);
    }
}
